# Maintainer: @naveen521kk on Github, Naveen M K <naveen521kk@gmail.com>

_realname=manim
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.14.0
pkgrel=1
pkgdesc="Animation engine for explanatory math videos (community edition) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://www.manim.community'
license=('MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-ffmpeg"  
  "${MINGW_PACKAGE_PREFIX}-python-click"
  "${MINGW_PACKAGE_PREFIX}-python-click-default-group"
  "${MINGW_PACKAGE_PREFIX}-python-colour"
  "${MINGW_PACKAGE_PREFIX}-python-isosurfaces"
  "${MINGW_PACKAGE_PREFIX}-python-numpy"
  "${MINGW_PACKAGE_PREFIX}-python-pillow"
  "${MINGW_PACKAGE_PREFIX}-python-scipy"
  "${MINGW_PACKAGE_PREFIX}-python-tqdm"
  "${MINGW_PACKAGE_PREFIX}-python-pydub"
  "${MINGW_PACKAGE_PREFIX}-python-pygments"
  "${MINGW_PACKAGE_PREFIX}-python-rich"
  "${MINGW_PACKAGE_PREFIX}-python-cairo"
  "${MINGW_PACKAGE_PREFIX}-python-manimpango"
  "${MINGW_PACKAGE_PREFIX}-python-networkx"
  "${MINGW_PACKAGE_PREFIX}-python-decorator"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-watchdog"
  "${MINGW_PACKAGE_PREFIX}-python-moderngl"
  "${MINGW_PACKAGE_PREFIX}-python-moderngl-window"
  "${MINGW_PACKAGE_PREFIX}-mapbox-earcut"
  "${MINGW_PACKAGE_PREFIX}-python-cloup"
  "${MINGW_PACKAGE_PREFIX}-python-requests"
  "${MINGW_PACKAGE_PREFIX}-python-screeninfo"
  "${MINGW_PACKAGE_PREFIX}-python-skia-pathops"
  "${MINGW_PACKAGE_PREFIX}-python-srt"
)
optdepends=("${MINGW_PACKAGE_PREFIX}-texlive-scheme-medium: For LaTeX support")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "${MINGW_PACKAGE_PREFIX}-cc")
source=(
  "${_realname}-${pkgver}.tar.gz"::"https://github.com/ManimCommunity/${_realname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
)
sha512sums=('e11ea6b8799f000845368945878fcafa84f80c06c5ee394b6532bec90d1f465e95d887b1e642302bba6f9dd424e359fe1551ba1f022667147b842295e173bf2f')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cd "${srcdir}"
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  sed -i 's/cloup>=0.7.0,<0.8.0/cloup/g' setup.py
  sed -i 's/mapbox-earcut>=0.12.10,<0.13.0/mapbox-earcut/g' setup.py
  sed -i 's/screeninfo>=0.6.7,<0.7.0/screeninfo/' setup.py
  sed -i 's/srt>=3.5.0,<4.0.0/srt/g' setup.py
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i "${_f}"
  done
  
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -Dm644 LICENSE.community "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.community"
}
